#define DEBUG
#include <cstdio>
#include <algorithm>

using namespace std;

const int maxm=300000;

class Segment {
public:
  int l, r, a;

  static bool cmp(Segment a, Segment b) {
    return a.l<b.l || (a.l==b.l && a.r>b.r);
  }
};

class Heap {
public:
  Heap *son, *bro;
  int size;
  long long v;

  Heap(long long val) {
    v = val;
    size = 1;
    son = bro = NULL;
  }
};

Heap* merge(Heap *a, Heap *b) {
  if (!a) {
    return b;
  }
  if (!b) {
    return a;
  }
  if (a->v>=b->v) {
    a->size+=b->size;
    b->bro = a->son;
    a->son = b;
    return a;
  } else {
    return merge(b, a);
  }
}

Heap* merges(Heap *a) {
  if (!a || !a->bro) {
    return a;
  } else {
    Heap *b=a->bro, *t=b->bro;
    a->bro = b->bro = NULL;
    return merge(merge(a, b), merges(t));
  }
}

Heap* sumHeap(Heap *a, Heap *b) {
  Heap *t;
  if (!a || a->size<b->size) {
    t = a, a = b, b = t;
  }
  static long long sum[maxm+1];
  int n;
  for (n=1; b; n++) {
    sum[n] = a->v+b->v;
    t = a;
    a = merges(a->son);
    delete t;
    t = b;
    b = merges(b->son);
    delete t;
  }
  for (int i=1; i<n; i++) {
    a = merge(a, new Heap(sum[i]));
  }
  return a;
}

class Tree {
public:
  int son[maxm+1], bro[maxm+1], a[maxm+1];
  Heap *g[maxm+1];

  void addSide(int fa, int o) {
    bro[o] = son[fa];
    son[fa] = o;
  }

  void solve(int o) {
    for (int i=son[o]; i; i=bro[i]) {
      solve(i);
    }
    g[o] = NULL;
    for (int i=son[o]; i; i=bro[i]) {
      if (g[i]) {
	g[o] = sumHeap(g[o], g[i]);
      }
    }
    g[o] = merge(g[o], new Heap(a[o]));
  }
};

void buildTree(Tree &a, Segment segs[], int n) {
  static int t[maxm+1];
  t[0] = t[1] = 1;
  for (int i=2; i<=n; i++) {
    for (; t[0] && segs[t[t[0]]].r<segs[i].r; t[0]--);
    a.addSide(t[t[0]], i);
    a.a[i] = segs[i].a;
    t[++t[0]] = i;
  }
}

int main() {
  freopen("cover.in", "r", stdin);
  freopen("cover.out", "w", stdout);

  static Segment segs[maxm+1];
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i=1; i<=m; i++) {
    scanf("%d %d %d", &segs[i].l, &segs[i].r, &segs[i].a);
  }

  segs[++m].l = 1;
  segs[m].r = n;

  sort(segs+1, segs+m+1, Segment::cmp);
  static Tree tree;
  buildTree(tree, segs, m);

  tree.solve(1);

  long long ans=0;
  for (int i=1; i<m; i++) {
    if (tree.g[1]) {
      ans += tree.g[1]->v;
      tree.g[1] = merges(tree.g[1]->son);
    }
    printf("%lld ", ans);
  }

  fclose(stdin);
  fclose(stdout);
  return 0;
}
